package cn.icanci.rec.admin.biz.service.impl;

import cn.icanci.rec.admin.biz.mapper.StrategyMapper;
import cn.icanci.rec.admin.biz.service.StrategyService;
import cn.icanci.rec.admin.dal.mongodb.common.PageList;
import cn.icanci.rec.admin.dal.mongodb.daointerface.StrategyDAO;
import cn.icanci.rec.admin.dal.mongodb.dateobject.StrategyDO;
import cn.icanci.rec.common.model.config.StrategyVO;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

/**
 * @author icanci
 * @since 1.0 Created in 2022/11/12 10:38
 */
@Service
public class StrategyServiceImpl implements StrategyService {
    @Resource
    private StrategyDAO    strategyDAO;
    @Resource
    private StrategyMapper strategyMapper;

    @Override
    public List<StrategyVO> queryAll() {
        return strategyMapper.dos2vos(strategyDAO.queryAll());
    }

    @Override
    public void save(StrategyVO strategy) {
        if (doInsert(strategy)) {
            strategyDAO.insert(strategyMapper.vo2do(strategy));
        } else {
            strategyDAO.update(strategyMapper.vo2do(strategy));
        }
    }

    @Override
    public StrategyVO queryById(String id) {
        return strategyMapper.do2vo(strategyDAO.queryOneById(id));
    }

    @Override
    public PageList<StrategyVO> queryPage(StrategyVO strategy, int pageNum, int pageSize) {
        PageList<StrategyDO> pageQuery = strategyDAO.pageQuery(strategyMapper.vo2do(strategy), pageNum, pageSize);
        return new PageList<>(strategyMapper.dos2vos(pageQuery.getData()), pageQuery.getPaginator());
    }
}
